<?php
session_start();
require_once 'C:\wamp\www\WEB\trunk\Projet_Web_2013_Client\Modele\BDDconnexion.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="imagetoolbar" content="no" />
        <title>Bienvenue sur EXia Store</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
        <script type="text/javascript" src="../Controleur/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
        <link rel="stylesheet" type="text/css" href="../Controleur/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
        <link rel ="stylesheet" href="Style.css" />
                <script src="../Helper/JQuery.js"></script>
        <script src="../Helper/Script.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {

                $("a.Detail").fancybox({
                    'titlePosition': 'inside',
                    'transitionIn': 'none',
                    'transitionOut': 'none'
                });

            });
        </script>


    </head>
    <header id="header">
        <table id="tableheader">
            <tr id="LigneCompte">
                <td id='MenuComptelog'>
                    <?php if (isset($_SESSION['Utilisateur'])) { ?>
                        <ul id ="ListeCompteLog">
                            <li id="BoutonListeTop"><a class ="Liens" href="Compte.php">Bonjour <?php echo $_SESSION['Utilisateur'][0]; ?></a></li>
                            <li id="BoutonListeTop"><a class="Liens" href="../Controleur/Authentification/logout.php"> [Se déconnecter]</a></li>
                        </ul>   
                        <?php
                    } else {
                        echo 'Vous n\'etes pas connecté';
                    }
                    ?></td>
                <td id="MenuCompte" >
                    <ul id ="ListeCompte">
                        <li id="BoutonListeTop"><a href ="Compte.php" class="Liens">Mon compte</a></li>
                        <li id="BoutonListeTop" ><a href ="MonPanier.php" class="Liens">Mon panier</a></li>
                        <li id="BoutonListeTop" ><a href ="Compte.php" class="Liens">Ma commande</a></li>
                        <li id="BoutonListeTop" ><a href ="Compte.php" class="Liens">Support</a></li>
                    </ul>
                </td>
            </tr>
            <tr id="BanniereSearch">
                <td>
                    <img id="banniere" src="Images/Exiastore2013.png">
                </td>

                <td id ="Recherche">
                    <form name="Recherche" method="POST" action="../Controleur/Recherche/rechercher.php">
                        <input type="text" name="description" >
                        <input type="submit" name="Rechercher" value="Rechercher">
                    </form>
                </td>
            </tr>
            <tr id="MenuAccueil">
                <td colspan ="2">
                    <ul id ="ListeAccueil">
                        <li id="BoutonListeBot"><a href ="../index.php" class="Liens">Accueil</a></li>
                        <li id="BoutonListeBot">CD</li>
                        <li id="BoutonListeBot">DVD</li>
                        <li id="BoutonListeBot">Livraison</li>
                        <li id="BoutonListeBot">Promotion</li>
                    </ul>
                </td>

            </tr>
        </table>
    </header>
    <body>
        <table id="Corps">
            <tr>
                <td id="TabArticle">
                    <nav id="MenuLeft">
                        <h1 id ="EnTeteMenuLeft">CD</h1>
                        <ul id ="ListeLeft">
                            <li>Rock</li>
                            <li>Rap</li>
                            <li>Electro</li>
                            <li>Classique</li>
                            <li>Autre</li>
                        </ul>
                    </nav>
                    <nav id="MenuLeft">
                        <h1 id ="EnTeteMenuLeft">DVD</h1>
                        <ul id ="ListeLeft">
                            <li>Action</li>
                            <li>Humour</li>
                            <li>Fantastique</li>
                            <li>Autre</li>
                        </ul>
                    </nav>
                </td>
                <td>

                    <table>
                        <tr>
                            <td>
                                Titre
                            </td>
                            <td>
                                Prix unitaire
                            </td>
                            <td>
                                Quantite
                            </td>
                            <td>
                                Prix total
                            </td>
                        </tr>
                        <?php
                        /*
                          foreach($_SESSION['panier'] as $ValueP){?>
                          <tr>
                          <td>
                          <?php var_dump($ValueP);
                          var_dump($ValueP['titre']);
                          ?>
                          </td>
                          <td>
                          Prix unitaire
                          </td>
                          <td>
                          Quantite
                          </td>
                          <td>
                          Prix total
                          </td>
                          </tr>
                          <?php }
                         */

                        class RQPanier extends BDDconnexion {

                            public function select_article() {
                                $i = 0;
                                foreach ($_SESSION['panier'] As $tab) {
                                    $rqt = "SELECT * FROM ARTICLE WHERE ID_ARTICLE = '" . $tab['ID_Article'] . "'";
                                    $res = $this->connexion()->query($rqt);
                                    $tabres[$i + 1] = $res->fetch();
                                    $tabres[$i + 1]["QuantiteC"] = $tab['Quantite'];

                                    $i++;
                                }
                                return @$tabres;
                            }

                        }

                        $panier = new RQPanier();
                        $pan = $panier->select_article();
                        
                        if (!empty($pan) && isset($pan)) {
                            foreach ($pan as $ligne) {
                                var_dump($ligne);
                                ?>
                                <tr id="ligne">
                                    <td>
                                        <p><?php echo $ligne['TITRE']; ?></p>
                                    </td>
                                    <td>
                                        <p><?php echo $ligne["PRIX_UNITAIRE"]. "€" ?></p>
                                    </td>
                                                                        <td>
                                        <p><?php echo $ligne["QuantiteC"] ?></p>
                                    </td>
                                    <td>
                                        <p><?php $prixtotal=$ligne["PRIX_UNITAIRE"] * $ligne['QuantiteC'];
                                                echo $prixtotal . "€" ?></p>
                                    </td>
                                    <td>
                                        <input style="width:50%; text-align:right;"type="text"id="quantite<?php echo $ligne["ID_ARTICLE"] ?>" value="<?php echo $ligne["QuantiteC"] ;?>" ></input>
                                    </td>
                                    <td>
                                        <input class="btn btn-primary" type="button" id="modifier<?php echo $ligne["ID_ARTICLE"] ?>" onclick="modifier(<?php echo $ligne["ID_ARTICLE"] ;?>);" value="Modifier"></input>
                                    </td>
                                    <td>
                                        <input class="btn btn-primary" type="button" id="supprimer<?php echo $ligne["ID_ARTICLE"] ?>" onclick="supprimer(<?php echo $ligne["ID_ARTICLE"]; ?>);" value="Supprimer"></input>
                                    </td>
                                </tr>
                                <?php
                            }
                        } else {
                            echo "le panier est vide";
                        }
                        ?>
                    </table>

                </td>
            </tr>
        </table>
    </body>
    <footer id="Footer">
        <table id="TableFooter">
            <tr>
                <td>

                </td>
            </tr>
        </table>
    </footer>
</html>